<?php 
require_once '../include.php';
checkLogined();
$rows=getAllCate();
if(!$rows){
	alertMes("没有相应分类，请先添加分类!!", "addCate.php");
}
$id=$_REQUEST['id'];
$proInfo=getProById($id);

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>edit project</title>
<link href="./styles/global.css"  rel="stylesheet"  type="text/css" media="all" />
 <link rel="stylesheet" href="styles/backstage.css">
<script type="text/javascript" src="./scripts/jquery-1.6.4.js"></script>
<script>

        $(document).ready(function(){
        	$("#selectFileBtn").click(function(){
        		$fileField = $('<input type="file" name="thumbs[]"/>');
        		$fileField.hide();
        		$("#attachList").append($fileField);
        		$fileField.trigger("click");
        		$fileField.change(function(){
        		$path = $(this).val();
        		$filename = $path.substring($path.lastIndexOf("\\")+1);
        		$attachItem = $('<div class="attachItem"><div class="left">a.gif</div><div class="right"><a href="#" title="删除附件">删除</a></div></div>');
        		$attachItem.find(".left").html($filename);
        		$("#attachList").append($attachItem);		
        		});
        	});
        	$("#attachList>.attachItem").find('a').live('click',function(obj,i){
        		$(this).parents('.attachItem').prev('input').remove();
        		$(this).parents('.attachItem').remove();
        	});


$("#btnDel").click(function() {  
	if(confirm("确定删除图像吗？")){
    	var id_array=new Array();  
		$('input[name="picIds"]:checked').each(function(){  
		    id_array.push($(this).val());//向数组中添加元素  
		    $(this).remove();
		    var imgId = "img" + $(this).val();
		    $("#"+imgId).remove();
		});  
		if(id_array.length < 1){
			alert("请选择要删除的图像！");
			return;
		}

		var idstr=id_array.join(',');//将数组元素连接起来以构建一个字符串  

		var url = "doAdminAction.php?act=delAlbumById";  
		$.ajax({  
			type: "POST",  
			url: url,  
			// dataType: "json",  
			data: {ids:idstr},  
			success: function(msg){  
				alert(msg); 
			}, 
			error: function(){  
             alert('删除图像出错！');  
         	}
		});  
	}
	  
});  

 });
        
</script>


</head>
<body>
<br/>
<h3>修改项目信息</h3>
<br/>
<form action="doAdminAction.php?act=editPro&id=<?php echo $id;?>" method="post" enctype="multipart/form-data">
<table cellpadding="5" cellspacing="0" class="table">
	<tr>
		<th align="right">项目名称</th>
		<td><input type="text" name="pName" class="search" value="<?php echo $proInfo['pName'];?>"/></td>
	</tr>
	<tr>
		<th align="right">项目分类</th>
		<td>
		<select name="cId" class="bui_select select">
			<?php foreach($rows as $row):?>
				<option value="<?php echo $row['id'];?>" <?php echo $row['id']==$proInfo['pId']?"selected='selected'":null;?>><?php echo $row['cName'];?></option>
			<?php endforeach;?>
		</select>
		</td>
	</tr>
	<tr>
		<th align="right">项目面积</th>
		<td><input type="text" name="pArea" class="search" value="<?php echo $proInfo['pArea'];?>"/></td>
	</tr>
	<tr>
		<th align="right">项目介绍</th>
		<td><input type="text" name="pDesc" class="search" value="<?php echo $proInfo['pDesc'];?>"/></td>
	</tr>
	<tr>
		<th align="right">委托单位</th>
		<td><input type="text" name="cUnit" class="search" value="<?php echo $proInfo['cUnit'];?>"/></td>
	</tr>
	<tr>
		<th align="right">设计内容</th>
		<td><input type="text" name="dDesc" class="search" value="<?php echo $proInfo['dDesc'];?>"/></td>
	</tr>
	<tr>
		<th align="right">设计时间</th>
		<td><input type="text" name="dTime" class="search" value="<?php echo $proInfo['dTime'];?>"/></td>
		
	</tr>
	<tr>
		<th align="right">项目图像</th>
		<td>
			<?php 
				$proImgs=getAllImgByProId($id);
				foreach($proImgs as $img):
			?>

				<input  type="checkbox" id="picIds" name="picIds" class="check" value=<?php echo $img['id'];?>>
				<img width="100" height="100" id="img<?php echo $img['id'];?>" src="uploads/<?php echo $img['albumPath'];?>" alt=""/> 

			<?php endforeach;?>
			<?php 
				if($proImgs){
			?>
				<!-- <input type="button" value="删除选中图片" id="btnDel"  class="btn" onclick="delPicture(<?php echo $row['id'];?>)"> -->
				<input type="button" value="删除选中图片" id="btnDel"  class="btn" />
			<?php }?>
			<br/>
			<a href="javascript:void(0)" id="selectFileBtn" class="btn">添加图像</a>
			
			<div id="attachList" class="attachList" class="clear"></div>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" class="btn" value="编辑项目"/></td>
	</tr>
</table>
</form>
</body>
</html>